﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Protocol;
using System.IO;
using MsgPack.Serialization;

namespace SocketServer.ServerBase
{
    public abstract class ClientRequestPackCommand<TMsgPack> 
        : CommandBase<ClientRequestPackSession, BinaryRequestInfo> where TMsgPack : class
    {
        public override void ExecuteCommand(ClientRequestPackSession session, BinaryRequestInfo requestInfo)
        {
            var serializer = SerializationContext.Default.GetSerializer<TMsgPack>();
            using (var stream = new MemoryStream(requestInfo.Body))
            {
                var unpackedObject = serializer.Unpack(stream) as TMsgPack;
                ExecuteCommand(session, unpackedObject);
            }           
        }

        public abstract void ExecuteCommand(ClientRequestPackSession session, TMsgPack pack);
    }
   
}
